import { useUserStore } from '@/store/modules/user'
const userStore = useUserStore()
export async function downloadFile(row: any) {
	const url = window.location.protocol + '//' + window.location.host + '/JGBStandardWebApi' + `/api/files/${row.systemFileName}/download`
	try {
		// 发起请求
		const response = await fetch(url, {
			method: 'GET',
			headers: {
				Authorization: userStore.token, // 在 Header 中传递 token
				'Content-Type': 'application/json' // 根据实际需求设置 Content-Type
			}
		})

		if (!response.ok) {
			throw new Error(`下载失败: ${response.statusText}`)
		}

		// 获取文件数据
		const blob = await response.blob()

		// 创建下载链接
		const downloadLink = document.createElement('a')
		downloadLink.href = URL.createObjectURL(blob)
		downloadLink.download = row.fileRealName // 设置下载文件名(根据实际需求修改)
		document.body.appendChild(downloadLink)
		downloadLink.click()
		document.body.removeChild(downloadLink)
	} catch (error) {
		console.error('下载过程中出错:', error)
	}
}
